New upstream version 1.1.9+ds1
authorBoyuan Yang <byang@debian.org>
Tue, 13 Aug 2024 16:48:28 +0000 (12:48 -0400)
committerBoyuan Yang <byang@debian.org>
Tue, 13 Aug 2024 16:48:28 +0000 (12:48 -0400)
25 files changed:
.github/FUNDING.yml [new file with mode: 0644]
.github/workflows/bazel.yml
.npmignore
BUILD.bazel
CMakeLists.txt
MODULE.bazel
MODULE.bazel.lock
README.md
data/scripts/find_target.py
data/scripts/merge.py
data/scripts/reverse.py
data/scripts/sort.py
data/scripts/sort_all.py
node/global.gypi
package.json
python/opencc/BUILD.bazel [new file with mode: 0644]
python/opencc/__init__.py
python/tests/BUILD.bazel [new file with mode: 0644]
python/tests/requirements_lock.txt [new file with mode: 0644]
python/tests/test_opencc.py
src/BUILD.bazel
src/Config.cpp
src/Config.hpp
src/SimpleConverter.cpp
src/tools/CommandLine.cpp

diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644 (file)
index 0000000..70e3ef3
--- /dev/null
@@ -0,0 +1 @@
+github: BYVoid
index f9ee8580ee93eb88a4f41ad677bd8f6c9dc37954..53716759985b98731aa6eb6316af29ae9220bca8 100644 (file)
@@ -16,5 +16,9 @@ jobs:
     steps:
       - uses: actions/checkout@v4
       - uses: bazelbuild/setup-bazelisk@v3
+      - name: Set up Python
+        uses: actions/setup-python@v5
+        with:
+          python-version: "3.12"
       - run: bazel build //:opencc
-      - run: bazel test --test_output=all //src/... //data/... //test/...
+      - run: bazel test --test_output=all //src/... //data/... //test/... //python/...
index 8a56f3b1822701e2a1518826a29cf1adbdce0d11..3db42abe7ebefe5a813e770230739f939fa137be 100644 (file)
@@ -1,3 +1,4 @@
+.bazelversion
 .npmignore
 .gitignore
 CMakeLists.txt
@@ -18,8 +19,9 @@ CMakeLists.txt
 /src/*TestBase.cpp
 /doc
 /data/scheme
+/data/scripts
 /deps/google-benchmark
-/deps/gtest*
+/deps/googletest*
 /deps/pybind*
 /deps/tclap*
 /bazel-*
index 6c61b49babf3f32b87bdb90fabe98d4cfae17ce4..263edc9b9610de1a523d569f4f4e5bd5b36ce281 100644 (file)
@@ -1,3 +1,6 @@
+load("@rules_cc//cc:defs.bzl", "cc_library")
+load("@rules_python//python:py_library.bzl", "py_library")
+
 package(default_visibility = ["//visibility:public"])
 
 cc_library(
@@ -17,3 +20,10 @@ cc_library(
         "//src:opencc",
     ],
 )
+
+py_library(
+    name = "py_opencc",
+    deps = [
+        "//python/opencc",
+    ],
+)
index 3393613e883e35ed63242da79b61f04f6cf56507..1d8c8e6fd88bf4bc0444726b2260026753a8b619 100644 (file)
@@ -42,7 +42,7 @@ set (PACKAGE_URL https://github.com/BYVoid/OpenCC)
 set (PACKAGE_BUGREPORT https://github.com/BYVoid/OpenCC/issues)
 set (OPENCC_VERSION_MAJOR 1)
 set (OPENCC_VERSION_MINOR 1)
-set (OPENCC_VERSION_REVISION 8)
+set (OPENCC_VERSION_REVISION 9)
 
 if (CMAKE_BUILD_TYPE MATCHES Debug)
   set (version_suffix .Debug)
index 8dd662153ff90ba1762fbceff0f44f9b276b3866..b59448e9d8b7a5549881e59bd2b0c984165778d7 100644 (file)
@@ -2,14 +2,29 @@
 
 module(
     name = "opencc",
-    version = "1.1.8",
+    version = "1.1.9",
     compatibility_level = 1,
 )
 
 bazel_dep(name = "darts-clone", version = "0.32")
-bazel_dep(name = "googletest", version = "1.15.0")
+bazel_dep(name = "googletest", version = "1.15.0", dev_dependency = True)
 bazel_dep(name = "marisa-trie", version = "0.2.6")
+bazel_dep(name = "platforms", version = "0.0.10")
+bazel_dep(name = "pybind11_bazel", version = "2.12.0")
 bazel_dep(name = "rapidjson", version = "1.1.0")
 bazel_dep(name = "rules_cc", version = "0.0.9")
 bazel_dep(name = "rules_python", version = "0.34.0")
 bazel_dep(name = "tclap", version = "1.2.5")
+
+
+python = use_extension("@rules_python//python/extensions:python.bzl", "python")
+python.toolchain(
+    python_version = "3.12",
+)
+pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
+pip.parse(
+    hub_name = "pip",
+    python_version = "3.12",
+    requirements_lock = "//python/tests:requirements_lock.txt",
+)
+use_repo(pip, "pip")
index cbb5f6a0fd47922d1646a9537cb26d160f35b68e..e794d2d28423883eae37c6c113af9d6060c1c87e 100644 (file)
         },
         "recordedRepoMappingEntries": []
       }
+    },
+    "@@pybind11_bazel~//:internal_configure.bzl%internal_configure_extension": {
+      "general": {
+        "bzlTransitiveDigest": "+F47SE20NlARCHVGbd4r7kkjg4OA0eCJcOd5fqKq4fQ=",
+        "usagesDigest": "iH2lKTfsNEpn2MqtGpBNwJrxbb2C7DiYmh/XuKgDtr8=",
+        "recordedFileInputs": {
+          "@@pybind11_bazel~//MODULE.bazel": "e6f4c20442eaa7c90d7190d8dc539d0ab422f95c65a57cc59562170c58ae3d34"
+        },
+        "recordedDirentsInputs": {},
+        "envVariables": {},
+        "generatedRepoSpecs": {
+          "pybind11": {
+            "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
+            "ruleClassName": "http_archive",
+            "attributes": {
+              "build_file": "@@pybind11_bazel~//:pybind11-BUILD.bazel",
+              "strip_prefix": "pybind11-2.12.0",
+              "urls": [
+                "https://github.com/pybind/pybind11/archive/v2.12.0.zip"
+              ]
+            }
+          }
+        },
+        "recordedRepoMappingEntries": [
+          [
+            "pybind11_bazel~",
+            "bazel_tools",
+            "bazel_tools"
+          ]
+        ]
+      }
     }
   }
 }
index e4edffb68b4b78b57e28d59abc5fa58dbaa24824..6605453f99b8c61a4e25022a8dedab2a54e0b28c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -27,7 +27,21 @@ Discussion (Telegram): https://t.me/open_chinese_convert
 
 ## Installation 安裝
 
-See [Download](https://github.com/BYVoid/OpenCC/wiki/Download).
+### Package Managers 包管理器
+
+* [Debian](https://tracker.debian.org/pkg/opencc)
+* [Ubuntu](https://launchpad.net/ubuntu/+source/opencc)
+* [Fedora](https://packages.fedoraproject.org/pkgs/opencc/opencc/)
+* [Arch Linux](https://archlinux.org/packages/extra/x86_64/opencc/)
+* [Mac](https://formulae.brew.sh/formula/opencc)
+* [Bazel](https://registry.bazel.build/modules/opencc)
+* [Node.js](https://npmjs.org/package/opencc)
+* [Python](https://pypi.org/project/OpenCC/)
+
+### Prebuilt 預編譯
+
+* Windows (x86_64): [Latest build](https://ci.appveyor.com/api/projects/Carbo/opencc/artifacts/OpenCC.zip?branch=master&job=Environment:%20nodejs_version=none;%20Platform:%20x64)
+* Windows (x86): [Latest build](https://ci.appveyor.com/api/projects/Carbo/opencc/artifacts/OpenCC.zip?branch=master&job=Environment:%20nodejs_version=none;%20Platform:%20x86)
 
 ## Usage 使用
 
@@ -64,7 +78,7 @@ See [demo.js](https://github.com/BYVoid/OpenCC/blob/master/node/demo.js) and [ts
 
 ### Python
 
-[PyPI](https://pypi.org/project/OpenCC/) `pip install opencc` (Windows, Linux, Mac)
+`pip install opencc` (Windows, Linux, Mac)
 
 ```python
 import opencc
@@ -84,6 +98,8 @@ int main() {
 }
 ```
 
+[Full example with Bazel](https://github.com/BYVoid/opencc-bazel-example)
+
 ### C
 
 ```c
index 4244949c32cffea2e9d5d15970834b286ae53bbb..7b2b4771ee846a071504e3d46c80d1e62b816781 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 import sys
index 680c90e8688bcb789f70763a84b110bdcf65fef4..01fcf511ee9b17344a53880c570c1dddbb8d3fa8 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 import codecs
index 746f887d33db95c3952d9de7ea7b2816d792880c..a87ae46747e92397b5aa86aad2316b4e6ef4bf1a 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 import sys
index f7d4dc5699e0e56fe05748dd6372f91a14590a35..6ad6e8cb9b024777653ba884d27c5d643515c2b6 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 import sys
 
index bd57ae735ff2c8e83fc3676beadf9a565825dd55..c742413edfb6907adcf507679da3bfd6c716ff2a 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 import glob
 import sys
index 523e649fe498f8da516a683a86841df098ca349d..ad7f4ae840e4951d1bf0d49dd7d48dea6fb6030e 100644 (file)
@@ -1,6 +1,6 @@
 {
   "variables": {
-    "opencc_version": "1.1.8"
+    "opencc_version": "1.1.9"
   },
   "target_defaults": {
     "defines": [
index 9f0f80d55cf209882d6d998791088f221470e268..83fe8a31b74878005a807cdd967a58b7eead419a 100644 (file)
@@ -1,6 +1,6 @@
 {
   "name": "opencc",
-  "version": "1.1.8",
+  "version": "1.1.9",
   "description": "Conversion between Traditional and Simplified Chinese",
   "author": "Carbo Kuo <byvoid@byvoid.com>",
   "license": "Apache-2.0",
diff --git a/python/opencc/BUILD.bazel b/python/opencc/BUILD.bazel
new file mode 100644 (file)
index 0000000..876b1ca
--- /dev/null
@@ -0,0 +1,15 @@
+load("@rules_python//python:py_library.bzl", "py_library")
+
+package(default_visibility = ["//visibility:public"])
+
+py_library(
+    name = "opencc",
+    srcs = ["__init__.py"],
+    data = [
+        "//data/config",
+        "//data/dictionary:binary_dictionaries",
+        "//data/dictionary:text_dictionaries",
+    ],
+    imports = [".."],
+    deps = ["//src:py_opencc"],
+)
index f77f80cf972836800199ac478fde54c7499c845c..3884bdc7ff5f6eab180b040708690ab0dc43a84a 100644 (file)
@@ -3,13 +3,18 @@ from __future__ import absolute_import, unicode_literals
 import os
 import sys
 
-from opencc.clib import opencc_clib
+try:
+    import opencc_clib               
+except ImportError:
+    from opencc.clib import opencc_clib
 
 __all__ = ['OpenCC', 'CONFIGS', '__version__']
 
 __version__ = opencc_clib.__version__
-_thisdir = os.path.dirname(os.path.abspath(__file__))
-_opencc_share_dir = os.path.join(_thisdir, 'clib', 'share', 'opencc')
+_this_dir = os.path.dirname(os.path.abspath(__file__))
+_opencc_share_dir = os.path.join(_this_dir, 'clib', 'share', 'opencc')
+_opencc_rootdir =  os.path.abspath(os.path.join(_this_dir, '..', '..'))
+_opencc_configdir = os.path.join(_opencc_rootdir, 'data', 'config')
 
 if sys.version_info.major == 2:
     text_type = unicode  # noqa
@@ -18,6 +23,8 @@ else:
 
 if os.path.isdir(_opencc_share_dir):
     CONFIGS = [f for f in os.listdir(_opencc_share_dir) if f.endswith('.json')]
+elif os.path.isdir(_opencc_configdir):
+    CONFIGS = [f for f in os.listdir(_opencc_configdir) if f.endswith('.json')]
 else:
     CONFIGS = []
 
@@ -39,7 +46,9 @@ class OpenCC(opencc_clib._OpenCC):
         if not config.endswith('.json'):
             config += '.json'
         if not os.path.isfile(config):
-            config = os.path.join(_opencc_share_dir, config)
+            config_under_share_dir = os.path.join(_opencc_share_dir, config)
+            if os.path.isfile(config_under_share_dir):
+                config = config_under_share_dir
         super(OpenCC, self).__init__(config)
         self.config = config
 
diff --git a/python/tests/BUILD.bazel b/python/tests/BUILD.bazel
new file mode 100644 (file)
index 0000000..a8ca166
--- /dev/null
@@ -0,0 +1,16 @@
+load("@pip//:requirements.bzl", "requirement")
+load("@rules_python//python:py_test.bzl", "py_test")
+
+py_test(
+    name = "test_opencc",
+    srcs = ["test_opencc.py"],
+    data = [
+        "//test/testcases",
+    ],
+    imports = [".."],
+    deps = [
+        "//python/opencc",
+        requirement("pytest"),
+        requirement("exceptiongroup"),
+    ],
+)
diff --git a/python/tests/requirements_lock.txt b/python/tests/requirements_lock.txt
new file mode 100644 (file)
index 0000000..330e274
--- /dev/null
@@ -0,0 +1,5 @@
+exceptiongroup==1.2.2
+iniconfig==2.0.0
+packaging==24.1
+pluggy==1.5.0
+pytest==8.3.2
index 8ca83b7ef68747c73241df38fd655466b2d6f8cb..31b2b04536ce3bebb649dbbe6e8eb1e948400281 100644 (file)
@@ -1,6 +1,9 @@
 from __future__ import unicode_literals
 
 import os
+import pytest
+import sys
+
 from glob import glob
 
 _this_dir = os.path.dirname(os.path.abspath(__file__))
@@ -39,3 +42,7 @@ def test_conversion():
         for text, ans in zip(intexts, anstexts):
             assert converter.convert(text) == ans, \
                 'Failed to convert {} for {} -> {}'.format(pref, text, ans)
+
+
+if __name__ == "__main__":
+    sys.exit(pytest.main(sys.argv[1:]))
index 550d3b864b4fe8d80a703f5e9c3b974ce96e966e..e1e5f24db80ba21a8e2d6a1df4242b3d2dcccf50 100644 (file)
@@ -1,4 +1,6 @@
+load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")
 load("@rules_cc//cc:defs.bzl", "cc_library")
+load("@rules_python//python:py_library.bzl", "py_library")
 
 package(default_visibility = ["//visibility:public"])
 
@@ -328,6 +330,18 @@ cc_library(
     ],
 )
 
+pybind_extension(
+    name = "opencc_clib",
+    srcs = ["py_opencc.cpp"],
+    deps = [":opencc"],
+)
+
+py_library(
+    name = "py_opencc",
+    data = [":opencc_clib"],
+    imports = ["."],
+)
+
 cc_library(
     name = "segmentation",
     srcs = ["Segmentation.cpp"],
index eee6e067ba0e16892cccb726738dbab55f20cde2..a8392b1e9077a2d56020d2790210d57cc7dc09fa 100644 (file)
@@ -222,6 +222,10 @@ Config::Config() : internal(new ConfigInternal()) {}
 
 Config::~Config() { delete reinterpret_cast<ConfigInternal*>(internal); }
 
+ConverterPtr Config::NewFromFile(const std::string& fileName) {
+  return NewFromFile(fileName, std::vector<std::string>{}, nullptr);
+}
+
 ConverterPtr Config::NewFromFile(const std::string& fileName,
                                  const std::vector<std::string>& paths,
                                  const char* argv0) {
index 1737d01bdc14578fcad9f11128ec80fe4738a90c..6b744b9aa39a169b4cacfd9a5d5e8c86f65c103a 100644 (file)
@@ -37,9 +37,11 @@ public:
   ConverterPtr NewFromString(const std::string& json,
                              const std::vector<std::string>& paths);
 
+  ConverterPtr NewFromFile(const std::string& fileName);
+
   ConverterPtr NewFromFile(const std::string& fileName,
-                           const std::vector<std::string>& paths = {},
-                           const char* argv0 = nullptr);
+                           const std::vector<std::string>& paths,
+                           const char* argv0);
 
 private:
   void* internal;
index 7b24ac6548bbb8a347be0de4d63c1da00141455b..b179751d91a96ab78a171d4081a0d34ff64b544b 100644 (file)
@@ -55,7 +55,7 @@ struct InternalData {
         paths_with_runfiles.push_back(
             bazel_runfiles->Rlocation("_main/data/dictionary"));
         return new InternalData(
-            config.NewFromFile(configFileName, paths_with_runfiles));
+            config.NewFromFile(configFileName, paths_with_runfiles, argv0));
       }
 #endif
       return new InternalData(config.NewFromFile(configFileName, paths, argv0));
index e029d3d36a99b15b9efcae7c15dfcfbcca99e336..568d1bbfd0597fe3f6e32fb79996e1988980d204 100644 (file)
@@ -197,7 +197,7 @@ int main(int argc, const char* argv[]) {
       outputFileName = Optional<std::string>(outputArg.getValue());
       noFlush = true;
     }
-    converter = config.NewFromFile(configFileName, pathArg.getValue());
+    converter = config.NewFromFile(configFileName, pathArg.getValue(), argv[0]);
     bool lineByLine = inputFileName.IsNull();
     if (lineByLine) {
       ConvertLineByLine();